package me.zk.practice1;

import lombok.SneakyThrows;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @Author: zhang kai
 * @Date: 2022/10/28
 * @Description:
 */
public class Solution3 {


    public void solution() {
        int num = 256;
        int sum = 0;
        while(num>0) {
            sum += num& 0xff;
            num >>= 8;
        }
        System.out.println(sum);
    }


    public static void main(String[] args) {
        int num = 256;
        int sum = 0;
        while(num>0) {
            sum += num& 0xff;
            num >>= 8;
        }
        System.out.println(sum);
    }
    public int[] levelOrder() {
        Queue queue = new LinkedList();
        short a;
        char b;
        return null;

    }

    public void a() throws UnsupportedEncodingException {
        String str = "0130165101 你好 1102   106          店舗１０６                                        オリコン            化粧品                                  1     00000151 ";
        String str1 = "";
        Charset charset = Charset.forName("Shift_jis");
        CharsetDecoder decoder = charset.newDecoder();
        CharsetEncoder encoder = charset.newEncoder();
        encoder.onMalformedInput(CodingErrorAction.REPORT);
        encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
//        encoder.replaceWith("☆".getBytes());
        try {
            ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(str));
            CharBuffer cbuf = decoder.decode(bbuf);
            str1 = cbuf.toString();
        } catch (CharacterCodingException cce) {
            String errorMessage = "Exception during character encoding/decoding: "
                    + cce.getMessage();
            System.out.println(errorMessage);
            cce.printStackTrace();
        }

        //        Unicode、ASCII、GBK、GB2312、UTF-8
        System.out.println(str.equals(new String(str.getBytes(), "UTF-8")));
        System.out.println(str1.equals(new String(str1.getBytes(), "Shift_jis")));
        System.out.println(str1.equals(new String(str1.getBytes(), "UTF-8")));
    }
}
